//
//  SwapContr.m
//  万州V7宝iOS客户端[ObjC]
//
//  Created by DimChum_Haul on 16/3/21.
//  Copyright © 2016年 沙罗双树831. All rights reserved.
//

#import "SwapContr.h"
#import "Masonry.h"
#import "UIView+Geometry.h"
#import "UIView+PhyMoVal.h"
#import "UIColor+ColorFullTemplate.h"

@interface SwapContr () <UIScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
{
    UIScrollView* swapScrollView;
    UIScrollView* topScrollView;
    UIView * topCommonView;
    UICollectionView* downFlowList;
}

@end

@implementation SwapContr
- (instancetype)init{
    if (self = [super init]) {
        
        swapScrollView = [[UIScrollView alloc] init];
        swapScrollView.backgroundColor = [UIColor purpleColor];
        [self.view addSubview:swapScrollView];
        swapScrollView.frame = CGRectMake(0, 0, kscreenW, kscreenH);
        swapScrollView.contentSize = CGSizeMake(0, kscreenH*3);
        swapScrollView.scrollEnabled = YES;
        
        topCommonView = [[UIView alloc] init];
        topCommonView.frame = CGRectMake(0, 0, kscreenW, kscreenH*0.25f);
        topCommonView.backgroundColor = [UIColor redColor];
        [UIView simplifyWithCornerRadius:topCommonView with:10.0f];
        [swapScrollView addSubview:topCommonView];
        
        topScrollView = [[UIScrollView alloc] init];
        topScrollView.frame = CGRectMake(0, CGRectGetMaxY(topCommonView.frame)+10, kscreenW,kscreenH/2);
        topScrollView.backgroundColor = [UIColor yellowColor];
        [self.view addSubview:topScrollView];
        topScrollView.delegate = self;
        topScrollView.contentSize = CGSizeMake(0, kscreenH);
        topScrollView.scrollEnabled = YES;
        
        UICollectionViewFlowLayout* layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing = 1.0f;
        layout.minimumInteritemSpacing = 1.0f;
        layout.itemSize = CGSizeMake(kscreenW-20, 44);
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        downFlowList = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        [swapScrollView addSubview:downFlowList];
        downFlowList.frame = CGRectMake(0, CGRectGetMaxY(topScrollView.frame)+10, kscreenW, 500);
        [downFlowList registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        downFlowList.dataSource = self;
        downFlowList.delegate = self;
        return self;
    }
    
    return nil;
}

- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}

-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell"
                                                                           forIndexPath:indexPath];
    cell.backgroundColor = [UIColor Heavy_ColorfulDay];
    return cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat Y = scrollView.contentOffset.y;
    CGFloat percentage = Y / (topScrollView.contentSize.height - topScrollView.GeoHeight);
    NSLog(@"百分比化--->%f/100",percentage);
    if (scrollView == topScrollView) {
        [swapScrollView setContentOffset:CGPointMake(0, Y*0.75f) animated:NO];
        CGAffineTransform position = CGAffineTransformMakeTranslation(0, -Y);
        scrollView.transform = position;
        if(percentage >= 1.2f ){
            topScrollView.delegate = nil;
            [swapScrollView setContentOffset:CGPointMake(0,kscreenH*1.25f) animated:YES];
        }
    }
}

@end
